package vues;

import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.util.Observable;
import java.util.Observer;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JPanel;
import javax.swing.JTextField;

import modele.ModeleChoixListe;
import modele.ModeleP;
import controleurs.ChampChoixCOntrolleur;
import controleurs.ListeChoixControleur;

public class SmallSearchBar extends JPanel implements Observer {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private ModeleChoixListe modelec;
	private JTextField champR;
	public SmallSearchBar(ModeleP modelep,Dimension prefDim){
		modelec=new ModeleChoixListe(modelep.getCollec(), modelep);
		this.setLayout(new GridBagLayout());
		champR=new JTextField("Recherche");
		champR.addCaretListener(new ChampChoixCOntrolleur(modelec));
		champR.setPreferredSize(prefDim);
		champR.setMinimumSize(new Dimension(100,23));
		String[] data=modelep.getCollec().getHeadTable(); 
		@SuppressWarnings({"unchecked", "rawtypes"})
		JComboBox type=new JComboBox(data); 
		type.addItemListener(new ListeChoixControleur(modelec));
		JButton changeAdvanced=new JButton("+");
		GridBagConstraints gbc=new GridBagConstraints();
		modelec.addObserver(this);
		gbc.insets=new Insets(1,2,1,2);
		gbc.gridx=0;
		gbc.gridy=0;
		//Taille de la barre de recherche
		gbc.gridheight=1;
		gbc.gridwidth=5;
		this.add(champR, gbc);
		//Ajout du type
		gbc.gridx=5;
		gbc.gridwidth=2;
		gbc.gridheight=1;
		this.add(type, gbc);
		//Ajout du bouton +
		gbc.gridx=7;
		gbc.gridwidth=GridBagConstraints.REMAINDER;
		this.add(changeAdvanced);
	}
	public void update(Observable arg0, Object arg1) {
		//AutoCompleteDecorator.decorate(champR, modelec.getPossibilites());
	}

}
